package service;

import mapper.ForumMapper;
import org.springframework.stereotype.Service;
import pojo.invitation;
import pojo.reply_detail;
import tools.Page;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/1/4.
 */
@Service("bookService")
public class ForumServiceImpl implements ForumService {
    @Resource
    ForumMapper bookMapper;

    public Page ForumList(Integer id, String title, Page pageObj) {
        // 查询总条数
        int totalCount = bookMapper.getCount(id,title);
        // 设置总数、总页数
        pageObj.setTotalCount(totalCount);
        // 如果总条数>0,说明数据库中有数据，再查询具体数据
        if (totalCount > 0) {
            // （用户一直点击下一页）如果当前页大于总页数，把总页数的值赋给当前页的值，显示最后一页的值
            if (pageObj.getCurrPageNo() > pageObj.getTotalPageCount())
                pageObj.setCurrPageNo(pageObj.getTotalPageCount());
            List<invitation> List = bookMapper.getInvitationList(id,title, (pageObj.getCurrPageNo() - 1) * pageObj.getPageSize(), pageObj.getPageSize());

            pageObj.setList(List);
        } else {
            pageObj.setCurrPageNo(0);
            pageObj.setList(new ArrayList<invitation>());
        }
        return pageObj;

    }
   /* public Page ReplyList(Integer id,Page pageObj){
        // 查询总条数
        int totalCount = bookMapper.getReplyCount(id);
        // 设置总数、总页数
        pageObj.setTotalCount(totalCount);
        // 如果总条数>0,说明数据库中有数据，再查询具体数据
        if (totalCount > 0) {
            // （用户一直点击下一页）如果当前页大于总页数，把总页数的值赋给当前页的值，显示最后一页的值
            if (pageObj.getCurrPageNo() > pageObj.getTotalPageCount())
                pageObj.setCurrPageNo(pageObj.getTotalPageCount());
            List<reply_detail> List = bookMapper.getReply_detailList(id,(pageObj.getCurrPageNo() - 1) * pageObj.getPageSize(), pageObj.getPageSize());

            pageObj.setList(List);
        } else {
            pageObj.setCurrPageNo(0);
            pageObj.setList(new ArrayList<invitation>());
        }
        return pageObj;

    }*/
   public int addRepaly(reply_detail reply){
       return bookMapper.addRepaly(reply);
   }

    public int deleteByInvitationId(int id){
        return bookMapper.deleteByInvitationId(id);
    }
    public int deleteByreplay_detailId(int id){
        return bookMapper.deleteByreplay_detailId(id);
    }
}
